package com.bytezero.supertest3;

/*
 * 
 * 
 */
public class CheckAccount extends Account
{
	private double overdraft; //可透支的限额
	
	
	
	public CheckAccount(int id, double balance, double annualInterestRate,double overdraft)
	{
		super(id, balance, annualInterestRate);
		this.overdraft = overdraft;
	}
	
	
	
	
	public double getOverdraft() {
		return overdraft;
	}




	public void setOverdraft(double overdraft) {
		this.overdraft = overdraft;
	}




	@Override
	public void withdraw(double amount) 
	{
		if(getBalance() >= amount)  //余额足够
		{
			//方式一 
			//setBalance(getBalance() - amount);
			
			//方式二
			super.withdraw(amount);
			//方式三
			//可以将父类的 private double balance;   //余额 改为 
			             //protected double balance
			
			
			
		}
		//余额不够   透支额度 + 余额消费
		else if(overdraft >=( amount - getBalance())) 
		{
			overdraft -= (amount - getBalance());
			
			//setBalance(0);
			//或者
			super.withdraw(getBalance());
			
		}
		else
		{
			System.out.println("超过可透支限额！");
		}
		
	}
	
	
	
	
	

}
























